let array = [/* [1,2,3],[8,9,4],[7,6,5] */]
var spiralArray = function(array) {
    if(array.length==0||array[0].length==0)return []
    let left=0,rigth=array[0].length-1,top=0,bottom=array.length-1
    let arr = []
    while(left<=rigth&&top<=bottom){
        for(let i=left;i<=rigth;i++){
            arr.push(array[top][i])
        }
         for(let i=top+1;i<=bottom;i++){
            arr.push(array[i][rigth]) 
        }
        if(left<rigth&&top<bottom){
            for(let i=rigth-1;i>=left;i--){
                arr.push(array[bottom][i])
            }
            for(let i=bottom-1;i>top;i--){
                arr.push(array[i][left])
            }
        }
        [left,rigth,top,bottom] = [left+1,rigth-1,top+1,bottom-1]
    }
    return arr
};
console.log(spiralArray(array));
